cmd.arg("--crate-name").arg(&unit.target.crate_name());
- for crate_type in crate_types.iter() {
- cmd.arg("--crate-type").arg(crate_type);
+ if !test {
+ for crate_type in crate_types.iter() {
+ cmd.arg("--crate-type").arg(crate_type);
+ }
}
let prefer_dynamic = (unit.target.for_host() &&
if test && unit.target.harness() {
cmd.arg("--test");
+ } else if test {
+ cmd.arg("--cfg").arg("test");
}
if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
assert_that(p.cargo("build").arg("-vv"),
execs().with_status(0).with_stderr_contains("\
-[..] warning: function is never used[..]
+[..]warning: function is never used[..]
"));
}
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
--out-dir {dir}{sep}target{sep}debug [..]`
-[RUNNING] `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \
+[RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \
-C debug-assertions [..]--test[..]`
", sep = SEP,
dir = p.root().display(), url = p.url())));
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
}
+
+#[test]
+fn cfg_test_even_with_no_harness() {
+ if !is_nightly() {
+ return
+ }
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ harness = false
+ doctest = false
+ "#)
+ .file("src/lib.rs", r#"
+ #[cfg(test)]
+ fn main() {
+ println!("hello!");
+ }
+ "#);
+ assert_that(p.cargo_process("test").arg("-v"),
+ execs().with_status(0)
+ .with_stdout("hello!\n")
+ .with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..]`
+[RUNNING] `[..]`
+"));
+}